package com.bjb.vr.operation.controller;

import com.bjb.vr.common.ao.ResDictionaryAo;
import com.bjb.vr.common.constant.ResDicType;
import com.bjb.vr.common.dto.SysTenant;
import com.bjb.vr.common.result.BaseErrorCode;
import com.bjb.vr.common.result.BaseResult;
import com.bjb.vr.common.result.CommonResult;
import com.bjb.vr.common.service.ResDictionaryService;
import com.bjb.vr.common.vo.ResDictionaryVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 运营端字典管理
 * @author: hujingbo
 * @create: 2022-08-12 14:54
 **/
@RestController
@RequestMapping("/api/operation/v1")
public class SysDictController {

    @Resource
    private ResDictionaryService dictionaryService;

    /**
     * 关联查询字典类型列表
     *
     * @return
     */
    @RequestMapping("/dict/list")
    public BaseResult queryDictList(@RequestBody ResDictionaryAo dictionaryAo) {
        List<ResDictionaryVo> dictionaryVos = dictionaryService.queryDictionaryByPeriodLink(dictionaryAo);
        return CommonResult.Ok().setResult(dictionaryVos);
    }

    /**
     * 客户配置管理-新增设备-查询设备类型列表
     *
     * @return
     */
    @RequestMapping("/dict/queryDevModeList")
    public BaseResult queryDevModeList() {
        List<ResDictionaryVo> dictionaryVos = dictionaryService.getResDictionaryList(ResDicType.DEVICE_TYPE.getType());
        return CommonResult.Ok().setResult(dictionaryVos);
    }

    /**
     * 添加字典
     *
     * @param resDictionaryAo
     * @return
     */
    @PostMapping("/dict/insert")
    public BaseResult addDictionary(@RequestBody ResDictionaryAo resDictionaryAo) {
        boolean success = dictionaryService.addDictionary(resDictionaryAo);
        if (!success) {
            return CommonResult.Fail(BaseErrorCode.ERROR_ADD);
        }
        return CommonResult.Ok();
    }

    /**
     * 更新字典状态
     *
     * @param resDictionaryAo
     * @return
     */
    @PostMapping("/dict/update")
    public BaseResult updateDictionary(@RequestBody ResDictionaryAo resDictionaryAo) {
        boolean success = dictionaryService.updateDictionary(resDictionaryAo);
        if (!success) {
            return CommonResult.Fail(BaseErrorCode.ERROR_UPDATE);
        }
        return CommonResult.Ok();
    }
}
